<template>
  <div class="hazTree">
    <div class="haz-header">
      调查对象分类
    </div>
    <div>
      <el-tree class="filter-tree"
            :data="treeData"
            :props="defaultProps"
            default-expand-all highlight-current :expand-on-click-node="false"
            check-on-click-node
            @check="categoryCheckHandler"
        ref="tree"></el-tree>
    </div>
  </div>
</template>

<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';
import {
    getWorkCategoryTree
} from '@/api/investWork';

@Component({
  components: {}
})
export default class HazTree extends Vue {
  private treeData: any = [
    {
      label: '承灾体',
      children: [
        {
          label: '公共服务设施',
          children: [
            {
              label: '学校'
            },
            {
              label: '医疗卫生机构'
            },
            {
              label: '提供住宿的社会服务机构'
            },
            {
              label: '公共文化场所'
            },
            {
              label: '旅游景区'
            }
          ]
        }
      ]
    }
  ]
  private defaultProps: any = {
    children: 'children',
    label: 'label'
  }
  categoryCheckHandler(data: any) {
    this.$emit('selected', data);
  }

  getCategoryTree(bigCategoryId?:number){
    getWorkCategoryTree({bigCategoryId: bigCategoryId}).then(res =>{
      if(res){
          this.treeData = res.data;
      }
    });
  }

  mounted(){
    this.getCategoryTree();
    (this as any).$bus.$on('categoryCheckedHandler',(item:any) =>{
     
        this.getCategoryTree(item.id);
    });
   
  }
   
}
</script>
<style lang="scss" scoped>
.hazTree{
  width: 260px;
  background-color: #ffffff;
  padding: 12px 0;
  .haz-header{
    height: 28px;
    line-height: 28px;
    color: #448f7d;
    padding-left: 18px;
    border-left: 3px solid #448f7d;
    font-size: 14px;
    font-weight: bold;
    background: linear-gradient(to right, #e1f5f1, rgba(255, 255, 255, 1));
  }
}
</style>
